home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / pas_all.zip / TI670.ASC < prev    next >
Text File  |  1992-02-28  |  5KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Turbo Pascal                           NUMBER  :  670
  8.   VERSION  :  6.0
  9.        OS  :  MS/PC DOS
  10.      DATE  :  February 28, 1992                        PAGE  :  1/4
  11.  
  12.     TITLE  :  Messaging Between Two Dialogs and Update Background
  13.               Events
  14.  
  15.  
  16.  
  17.  
  18.   {
  19.      This program will create two modeless dialog boxes and will
  20.      allow only one dialog to be created at any time.
  21.  
  22.      Additionally, it demonstrates how to broadcast messages to
  23.      background windows and update information without changing
  24.      the selected dialog.
  25.  
  26.   }
  27.   {$X+}
  28.  
  29.   Program DialogCommunication;
  30.  
  31.   uses Objects, Drivers, Views, Menus, Dialogs, App, Crt;
  32.   const
  33.     cmDialog1 = 100;
  34.     cmDialog2 = 101;
  35.     cmDialog1Button = 200;
  36.     cmDialog2Button = 201;
  37.  
  38.   type
  39.  
  40.    PHelloApp = ^THelloApp;
  41.     THelloApp = object(TApplication)
  42.       procedure MakeDialog;
  43.       procedure HandleEvent(var Event: TEvent); virtual;
  44.       procedure InitMenuBar; virtual;
  45.       procedure InitStatusLine; virtual;
  46.     end;
  47.  
  48.     PMyDialog1 = ^TMyDialog1;
  49.     TMyDialog1 = object(TDialog)
  50.       procedure MakeDialog2;
  51.       procedure HandleEvent(var Event:TEvent); virtual;
  52.     end;
  53.  
  54.     PMyDialog2 = ^TMyDialog2;
  55.     TMyDialog2 = object(TMyDialog1)
  56.       procedure HandleEvent(var Event:TEvent); virtual;
  57.     end;
  58.  
  59.   procedure TMyDialog1.HandleEvent(var Event: TEvent);
  60.   var
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.   PRODUCT  :  Turbo Pascal                           NUMBER  :  670
  74.   VERSION  :  6.0
  75.        OS  :  MS/PC DOS
  76.      DATE  :  February 28, 1992                        PAGE  :  2/4
  77.  
  78.     TITLE  :  Messaging Between Two Dialogs and Update Background
  79.               Events
  80.  
  81.  
  82.  
  83.  
  84.     AreYouThere: PView;
  85.   begin
  86.     TDialog.HandleEvent(Event);
  87.     if Event.What = evCommand then
  88.       begin
  89.         case Event.Command of
  90.            cmDialog1Button:
  91.              begin
  92.                AreYouThere:= Message(DeskTop, evBroadcast,
  93.   cmDialog2, nil);
  94.                if AreYouThere = nil then
  95.                   MakeDialog2
  96.                 else
  97.                   ClearEvent(Event);
  98.              end
  99.         else
  100.           Exit;
  101.         end;
  102.           ClearEvent(Event);
  103.       end;
  104.   end;
  105.  
  106.   procedure TMyDialog1.MakeDialog2;
  107.   var
  108.     Dialog2: PMyDialog2;
  109.     R: TRect;
  110.     Button: PButton;
  111.   begin
  112.     R.Assign(1,1,40,20);
  113.     Dialog2:= New(PMyDialog2, init(R,'Dialog2'));
  114.     R.Assign(10,10,20,12);
  115.     Button:= New(PButton,Init(R,'Beep', cmDialog2Button,
  116.   bfdefault));
  117.     Dialog2^.Insert(Button);
  118.     DeskTop^.Insert(Dialog2);
  119.   end;
  120.  
  121.   procedure TMyDialog2.HandleEvent(var Event: TEvent);
  122.   begin
  123.     case Event.Command of
  124.       cmDialog2: begin
  125.                    sound(2000); delay(10); nosound;
  126.                    Title:=newstr('Hello world');
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.   PRODUCT  :  Turbo Pascal                           NUMBER  :  670
  140.   VERSION  :  6.0
  141.        OS  :  MS/PC DOS
  142.      DATE  :  February 28, 1992                        PAGE  :  3/4
  143.  
  144.     TITLE  :  Messaging Between Two Dialogs and Update Background
  145.               Events
  146.  
  147.  
  148.  
  149.  
  150.                    ReDraw;
  151.                    ClearEvent(Event);
  152.                  end;
  153.     end;
  154.     TDialog.HandleEvent(Event);
  155.     if Event.What = evCommand then
  156.       begin
  157.         case Event.Command of
  158.            cmDialog2Button: begin
  159.                               Sound(1000); delay(100); NoSound;
  160.                             end;
  161.         else
  162.           Exit;
  163.         end;
  164.           ClearEvent(Event);
  165.       end;
  166.   end;
  167.  
  168.   { THelloApp }
  169.  
  170.   procedure THelloApp.MakeDialog;
  171.   var
  172.     R:TRect;
  173.     Button1: PButton;
  174.     Dialog1: PMyDialog1;
  175.   begin
  176.     R.Assign(25, 5, 65, 16);
  177.     Dialog1:= New(PMyDialog1, init(R,'Dialog1'));
  178.     R.Assign(16, 8, 38, 10);
  179.     Button1:= New(PButton, Init(R,'Call Dialog2', cmDialog1Button,
  180.   bfDefault));
  181.     Dialog1^.Insert(Button1);
  182.     DeskTop^.Insert(Dialog1);
  183.   end;
  184.  
  185.   procedure THelloApp.HandleEvent(var Event: TEvent);
  186.   begin
  187.     TApplication.HandleEvent(Event);
  188.     if Event.What = evCommand then
  189.       begin
  190.         case Event.Command of
  191.            cmDialog1:begin
  192.                        MakeDialog;
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.   PRODUCT  :  Turbo Pascal                           NUMBER  :  670
  206.   VERSION  :  6.0
  207.        OS  :  MS/PC DOS
  208.      DATE  :  February 28, 1992                        PAGE  :  4/4
  209.  
  210.     TITLE  :  Messaging Between Two Dialogs and Update Background
  211.               Events
  212.  
  213.  
  214.  
  215.  
  216.                      end;
  217.         else
  218.           Exit;
  219.         end;
  220.           ClearEvent(Event);
  221.        end;
  222.   end;
  223.  
  224.   procedure THelloApp.InitMenuBar;
  225.   var
  226.     R: TRect;
  227.   begin
  228.     GetExtent(R);
  229.     R.B.Y := R.A.Y + 1;
  230.     MenuBar := New(PMenuBar, Init(R, NewMenu(
  231.       NewSubMenu('~O~pen Dialogs', hcNoContext, NewMenu(
  232.         NewItem('~D~ialog1','', 0, cmDialog1, hcNoContext,
  233.         NewLine(
  234.         NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit,
  235.           hcNoContext, nil)))), nil))));
  236.   end;
  237.  
  238.   procedure THelloApp.InitStatusLine;
  239.   var
  240.     R: TRect;
  241.   begin
  242.     GetExtent(R);
  243.     R.A.Y := R.B.Y-1;
  244.     StatusLine := New(PStatusLine, Init(R,
  245.       NewStatusDef(0, $FFFF,
  246.         NewStatusKey('', kbF10, cmMenu,
  247.         NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit, nil)), nil)));
  248.   end;
  249.  
  250.   var
  251.     HelloWorld: THelloApp;
  252.  
  253.   begin
  254.     HelloWorld.Init;
  255.     HelloWorld.Run;
  256.     HelloWorld.Done;
  257.   end.
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.